home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------
- TileWindows
- by Raffi Kasparian
- ----------------------------------------------------*/
- #define StackingOffset 10
-
- void TileWindows(enclosingRectPtr, windowPtrArray,
- windowCount, pixelsBetween,
- minHorzSize, minVertSize)
-
- Rect *enclosingRectPtr;
- WindowPtr windowPtrArray[];
- unsigned short windowCount;
- unsigned short pixelsBetween;
- unsigned short minHorzSize;
- unsigned short minVertSize;
-
- #define mx minHorzSize
- #define my minVertSize
- #define d pixelsBetween
-
- #define struc ((WindowPeek)(windowPtrArray[num]))->strucRgn
- #define strucL (**struc).rgnBBox.left
- #define strucT (**struc).rgnBBox.top
- #define strucR (**struc).rgnBBox.right
- #define strucB (**struc).rgnBBox.bottom
-
- #define cont ((WindowPeek)(windowPtrArray[num]))->contRgn
- #define contL (**cont).rgnBBox.left
- #define contT (**cont).rgnBBox.top
- #define contR (**cont).rgnBBox.right
- #define contB (**cont).rgnBBox.bottom
-
- #define pBits windowPtrArray[num]->portBits.bounds
- #define pBitsL pBits.left
- #define pBitsT pBits.top
- #define pBitsR pBits.right
- #define pBitsB pBits.bottom
-
- #define pRect windowPtrArray[num]->portRect
- #define pRectL pRect.left
- #define pRectT pRect.top
- #define pRectR pRect.right
- #define pRectB pRect.bottom
-
- {
- register short dL, dT, dR, dB, BR, x, y, maxx, maxy,
- num, rL, rT, rR, rB;
- Rect er = *enclosingRectPtr;
-
- #define erL er.left
- #define erT er.top
- #define erR er.right
- #define erB er.bottom
-
- num = 0;
-
- while (true) {
-
- maxy = (erB - erT + d)/(my + d);
- maxx = (erR - erL + d)/(mx + d);
- if ((BR = maxx * maxy) > windowCount) {
- maxx = (windowCount - 1) / maxy + 1;
- maxy = (windowCount - 1) / maxx + 1;
- BR = windowCount;
- }
- BR--;
-
- if (num <= BR) {
- mx = ((erR - erL) - ((maxx - 1) * d)) / maxx;
- my = ((erB - erT) - ((maxy - 1) * d)) / maxy;
- }
-
- rT = erT - (my + d);
- for (y = 1; y <= maxy; y++) {
- rL = erL - (mx + d);
- rT += my + d;
- rB = (y == maxy) && (num <= BR) ? erB : rT + my;
- for (x = 1; x <= maxx; x++, num++) {
-
- rL += mx + d;
- rR = ((x == maxx) && (num <= BR)) ||
- (num == BR) ? erR : rL + mx;
-
- dL = rL - strucL;
- dT = rT - strucT;
- dR = rR - strucR;
- dB = rB - strucB;
-
- SetRectRgn(struc, rL, rT, rR, rB);
- SetRectRgn(cont, contL + dL, contT + dT,
- contR + dR, contB + dB);
-
- pBitsL -= dL;
- pBitsT -= dT;
- pBitsR -= dL;
- pBitsB -= dT;
-
- pRectR = contR - contL + pRectL;
- pRectB = contB - contT + pRectT;
-
- if (num == windowCount - 1) {
- PaintBehind((WindowPeek)FrontWindow(),
- GrayRgn);
- CalcVisBehind((WindowPeek)FrontWindow(),
- GrayRgn);
- return;
- }
- }
- }
- if (erR - erL - StackingOffset >= mx)
- erL += StackingOffset;
- if (erB - erT - StackingOffset >= my)
- erT += StackingOffset;
- }
- }
-